using Cysharp.Threading.Tasks;
using DG.Tweening;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public partial class InfoPanel : UIPanel
{
    private const string path = "Assets/Prefab/InfoPanel.prefab";

    public string m_ContentText = "";
    public InfoPanel() : base(new UIType(path))
    {
    }

    public async override void OnEnter()
    {
        base.OnEnter();

        SetContent(m_ContentText);

        float moveDistance = ParentRectTransform.sizeDelta.x / 2 + UIObj.transform.parent.GetComponent<RectTransform>().sizeDelta.x / 2;

        ParentRectTransform.DOAnchorPosX(ParentRectTransform.anchoredPosition.x - moveDistance, 1);

        await UniTask.Delay(TimeSpan.FromSeconds(1));

        AddInputEventCallback();
    }
    public async override UniTask OnStop(bool useAnim)
    {
        await base.OnStop(useAnim);

        if (useAnim)
        {
            float moveDistance = ParentRectTransform.sizeDelta.x / 2 + UIObj.transform.parent.GetComponent<RectTransform>().sizeDelta.x / 2;

            ParentRectTransform.DOAnchorPosX(ParentRectTransform.anchoredPosition.x + moveDistance, 1);

            await UniTask.Delay(TimeSpan.FromSeconds(1));
        }

        RemoveInputEventCallback();
    }
    public virtual void SetContent(string contentText)
    {
        m_InfoContentTMP.SetText(contentText);
    }
    private void AddInputEventCallback()
    {
        m_CancleButton.onClick.AddListener(async() =>
        {
            await PanelManager.Instance.ClosePanel(this);
        });
    }
    private void RemoveInputEventCallback()
    {
        m_CancleButton.onClick.RemoveAllListeners();
    }
}
